library OperationSilentHillMAIN requires LegacySystem, LegacyExperienceSystem

    /*
    udg_DMKillingSpree[99] = Immortal Dummy Revive Rate (higher value for higher ranked squads)

    call SetSkyModel( "Environment\\Sky\\FelwoodSky\\FelwoodSky.mdl" )
    call SetTerrainFogEx( 0, 800.0, 2750.0, 0.550, 0.000, 0.000, 0.000 ) //1400, 3000, 0.75
    call SetDayNightModels( "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleTerrain\\DNCAshenvaleTerrain.mdl", "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleUnit\\DNCAshenvaleUnit.mdl" )
    call SetDayNightModels("","")

    Mode 1 : Normal
    Mode 2 : Boot
    Mode 3 : DM
    Mode 4 : Single Player
    Mode 5 : DM over

    */

	
		
	globals
		private unit            udg_EvilSheep              = null
		rect                    udg_PlayerSpawnBoundary    = null
    endglobals
    
	
    private function TriggerEventInitialize takes nothing returns nothing
        local player p = GetEnumPlayer()
		
		if GetPlayerSlotState(p) != PLAYER_SLOT_STATE_EMPTY and GetPlayerController(p) == MAP_CONTROL_USER then
			//call BJDebugMsg(GetPlayerName(p))
			
			if GetPlayerId(p) == 9 or GetPlayerId(p) == 11 then
				call CustomDefeatBJ(p, "Don't abuse bot commands please.")
				return
			endif
		endif

		//9,11 are AI
		
        call SetPlayerTechMaxAllowed(p,'H008',0)
        call SetPlayerTechMaxAllowed(p,'H004',0)
        call SetPlayerTechMaxAllowed(p,'H006',0)
        call SetPlayerTechMaxAllowed(p,'H007',0) //Combat Engineer
        call SetPlayerTechMaxAllowed(p,'H005',0) //Machine Gunner
        call SetPlayerTechMaxAllowed(p,'H003',0) //Marksman
        call SetPlayerTechMaxAllowed(p,'H00N',0) //MQ-3 Predator
        call SetPlayerTechMaxAllowed(p,'H00J',0) //Infantry Unit Leader
        call SetPlayerTechMaxAllowed(p,'H00O',0) //Assaultman
        call SetPlayerTechMaxAllowed(p,'H00S',0) //Sniper
		
		call SetPlayerAbilityAvailable(p, 'A03J', false)
		call SetPlayerAbilityAvailable(p, 'A020', false)
	
        call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,1)
        call SetPlayerState(p,PLAYER_STATE_RESOURCE_FOOD_CAP,1)

    endfunction

    private function ItemInitialize takes nothing returns nothing

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "Engineer"
        call SetB("Engineer",'H007',true) //Engineer
        call SetB("Engineer",'I009',true) //Browning
        call SetB("Engineer",'I008',true) //Benelli
        call SetB("Engineer",'z004',true) //Mini Engineer

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "armor"
        call SetB("armor",'rde1',true) //Kevlar
        call SetB("armor",'I001',true) //Composite
        call SetB("armor",'I005',true) //Reactive
        call SetB("armor",'I00Z',true) //Nano Body Armor

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "M240G"
        call SetB("M240G",'H000',true) //Firebat
        call SetB("M240G",'H008',true) //Delta Force
        call SetB("M240G",'H003',true) //Marksman
        call SetB("M240G",'z00F',true) //Mini Marksman
        call SetB("M240G",'z00G',true) //Mini Sniper
        call SetB("M240G",'H007',true) //Engineer
        call SetB("M240G",'I000',true) //M240G Machine Gun
        call SetB("M240G",'z009',true) //Mini Flamethrower
        call SetB("M240G",'z004',true) //Mini Engineer

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "SAMR"
        call SetB("SAMR",'H000',true) //Flamethrower
        call SetB("SAMR",'H005',true) //Machine Gunner
        call SetB("SAMR",'H007',true) //Engineer
        call SetB("SAMR",'I007',true) //SAM-R
        call SetB("SAMR",'z009',true) //Mini Flamethrower
        call SetB("SAMR",'z004',true) //Mini Engineer
        call SetB("SAMR",'z000',true) //Mini Auto Rifleman

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "ammo"
        call SetB("ammo",'I002',true) //AP
        call SetB("ammo",'ckng',true) //U238
        call SetB("ammo",'I00O',true) //TX-1
        call SetB("ammo",'H000',true) //Flamethrower
        call SetB("ammo",'z009',true) //Mini Flamethrower

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "miningpick"
        call SetB("miningpick",'rump',true) //Rusty mining pick
        call SetB("miningpick",'h00E',true) //Predator

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "blastocyst"
        call SetB("blastocyst",'I00A',true) //Blastocyst
        call SetB("blastocyst",'h00E',true) //Predator

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "aviationfuel"
        call SetB("aviationfuel",'I019',true) //Aviation Fuel
        call SetB("aviationfuel",'h00E',true) //Predator

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "sentry"
        call SetB("sentry",'I017',true) //Surveillance Sentry
        call SetB("sentry",'h00E',true) //Predator

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "kilo"
        call SetB("kilo",'I018',true) //Marine Corpse
        call SetB("kilo",'h00E',true) //Predator

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "M29"
        call SetB("M29",'H000',true) //Flamethrower
        call SetB("M29",'H005',true) //Heavy Support
        call SetB("M29",'H003',true) //Marksman
        call SetB("M29",'z00F',true) //Mini Marksman
        call SetB("M29",'z00G',true) //Mini Sniper
        call SetB("M29",'H007',true) //Engineer
        call SetB("M29",'I00B',true) //XM29
        call SetB("M29",'z009',true) //Mini Flamethrower
        call SetB("M29",'z004',true) //Mini Engineer
        call SetB("M29",'z000',true) //Mini Auto Rifleman

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "Hecate"
        call SetB("Hecate",'H007',true) //Engineer
        call SetB("Hecate",'Hpal',true) //Rifleman
        call SetB("Hecate",'H004',true) //FO
        call SetB("Hecate",'H005',true) //Heavy Support
        call SetB("Hecate",'H003',true) //Marksman
        call SetB("Hecate",'z00F',true) //Mini Marksman
        call SetB("Hecate",'z00G',true) //Mini Sniper
        call SetB("Hecate",'H002',true) //Doc
        call SetB("Hecate",'H00J',true) //IUL
        call SetB("Hecate",'z00E',true) //Mini IUL
        call SetB("Hecate",'H006',true) //Force Recon
        call SetB("Hecate",'H008',true) //Delta Force
        call SetB("Hecate",'H00O',true) //Assaultman
        call SetB("Hecate",'I003',true) //Hecate
        call SetB("Hecate",'z008',true) //Mini Rifleman
        call SetB("Hecate",'z000',true) //Mini Auto Rifleman
        call SetB("Hecate",'z001',true) //Mini Doc
        call SetB("Hecate",'z004',true) //Mini Engineer

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "Jackhammer"
        call SetB("Jackhammer",'H000',true) //Firebat
        call SetB("Jackhammer",'Hpal',true) //Grunt
        call SetB("Jackhammer",'H004',true) //ALO
        call SetB("Jackhammer",'H005',true) //Heavy Support
        call SetB("Jackhammer",'H003',true) //Marksman
        call SetB("Jackhammer",'z00F',true) //Mini Marksman
        call SetB("Jackhammer",'z00G',true) //Mini Sniper
        call SetB("Jackhammer",'H002',true) //Doc
        call SetB("Jackhammer",'H00J',true) //IUL
        call SetB("Jackhammer",'z00E',true) //Mini IUL
        call SetB("Jackhammer",'H006',true) //Force Recon
        call SetB("Jackhammer",'H008',true) //Delta Force
        call SetB("Jackhammer",'H00O',true) //Assaultman
        call SetB("Jackhammer",'I00X',true) //Pancor Jackhammer
        call SetB("Jackhammer",'z008',true) //Mini Rifleman
        call SetB("Jackhammer",'z000',true) //Mini Auto Rifleman
        call SetB("Jackhammer",'z009',true) //Mini Flamethrower
        call SetB("Jackhammer",'z001',true) //Mini Doc

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "HeavyWeapons"
        call SetB("HeavyWeapons",'I003',true) //Hecate
        call SetB("HeavyWeapons",'I000',true) //M240G
        call SetB("HeavyWeapons",'I00B',true) //XM-29
        call SetB("HeavyWeapons",'I007',true) //SAM-R
        call SetB("HeavyWeapons",'I00I',true) //SMAW
        call SetB("HeavyWeapons",'I00H',true) //XML-9C Shiva
        call SetB("HeavyWeapons",'nvl2',true) //Father A
        call SetB("HeavyWeapons",'nvil',true) //Father B

        set udg_nItemLists = udg_nItemLists + 1
        set udg_ItemLists[udg_nItemLists] = "LightWeapons"
        call SetB("LightWeapons",'I009',true) //Browning
        call SetB("LightWeapons",'I008',true) //Benelli
        call SetB("LightWeapons",'I00N',true) //M320
        call SetB("LightWeapons",'nvl2',true) //Father A
        call SetB("LightWeapons",'nvil',true) //Father B

    endfunction

    private function NumberPlayers takes nothing returns nothing
        local integer i = 1
        local integer sorted = 0
        set udg_Pcolors[1] = "|cffff0000"
        set udg_Pcolors[2] = "|cff0000ff"
        set udg_Pcolors[3] = "|cff00ffff"
        set udg_Pcolors[4] = "|cff551a8b"
        set udg_Pcolors[5] = "|cffffff00"
        set udg_Pcolors[6] = "|cffffa500"
        set udg_Pcolors[7] = "|cff008b00"
        set udg_Pcolors[8] = "|cffda70d6"
        set udg_Pcolors[9] = "|cff696969"
        set udg_Pcolors[11] = "|cff4682b4"
        loop
            exitwhen i>12
            if GetPlayerSlotState(Player(i-1))==PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i-1))==MAP_CONTROL_USER then
                set udg_Players = udg_Players + 1
                set udg_Sorted[udg_Players] = i
            endif
            set i=i+1
        endloop
        set udg_InitialPlayers = udg_Players

        if udg_Players>=5 then
            set udg_Spawn = 5
            call SetPlayerHandicap(Player(13),0.7+I2R(udg_InitialPlayers)*0.01+0.01*I2R(udg_Players-5))
            call SetPlayerHandicap(Player(14),0.7+I2R(udg_InitialPlayers)*0.01+0.01*I2R(udg_Players-5))
        elseif udg_Players == 4 then
			set udg_Spawn = 4
			call SetPlayerHandicap(Player(13),0.75)
			call SetPlayerHandicap(Player(14),0.75)
		else
			call SetPlayerHandicap(Player(13),0.70)
			call SetPlayerHandicap(Player(14),0.70)
            set udg_Spawn = 3
        endif
        set i=1
        loop
            exitwhen sorted==1
            set sorted = 1
            set i=1
            loop
                exitwhen i>=udg_Players
                if udg_Experience[udg_Sorted[i]]<udg_Experience[udg_Sorted[i+1]] then
                    call mSortedSwap(i,i+1)
                    set sorted = 0
                endif
                set i=i+1
            endloop
        endloop
    endfunction

    private function InitRanks takes nothing returns nothing
        local integer A = 1

        call SetS("RankN",1,"Pvt.")
        call SetS("RankN",2,"Pfc.")
        call SetS("RankN",3,"LCpl.")
        call SetS("RankN",4,"Cpl.")
        call SetS("RankN",5,"Sgt.")
        call SetS("RankN",6,"SSgt.")
        call SetS("RankN",7,"GySgt.")
        call SetS("RankN",8,"2Lt.")
        call SetS("RankN",9,"1Lt.")
        call SetS("RankN",10,"Capt.")
        call SetS("RankN",11,"Maj.")
        call SetS("RankN",12,"LtCol.")
        call SetS("RankN",13,"Col.")
        call SetS("RankN",14,"BGen.")
        call SetS("RankN",15,"MajGen.")
        call SetS("RankN",16,"LtGen.")
        call SetS("RankN",17,"Gen.")
        call SetS("RankN",18,"XPLimit")

        call SetS("RankFN",1,"Private")
        call SetS("RankFN",2,"Private First Class")
        call SetS("RankFN",3,"Lance Corporal")
        call SetS("RankFN",4,"Corporal")
        call SetS("RankFN",5,"Sergeant")
        call SetS("RankFN",6,"Staff Sergeant")
        call SetS("RankFN",7,"Gunnery Sergeant")
        call SetS("RankFN",8,"2nd Lieutenant")
        call SetS("RankFN",9,"1st Lieutenant")
        call SetS("RankFN",10,"Captain")
        call SetS("RankFN",11,"Major")
        call SetS("RankFN",12,"Lieutenant Colonel")
        call SetS("RankFN",13,"Colonel")
        call SetS("RankFN",14,"Brigadier General")
        call SetS("RankFN",15,"Major General")
        call SetS("RankFN",16,"Lieutenant General")
        call SetS("RankFN",17,"General")
        call SetS("RankFN",18,"XPLimit")

        call SetI("XP",1,0)
        call SetI("XP",2,500)
        call SetI("XP",3,1500)
        call SetI("XP",4,5000)
        call SetI("XP",5,10000)
        call SetI("XP",6,20000)
        call SetI("XP",7,35000)
        call SetI("XP",8,50000)
        call SetI("XP",9,65000)
        call SetI("XP",10,80000)
        call SetI("XP",11,120000)
        call SetI("XP",12,180000)
        call SetI("XP",13,240000)
        call SetI("XP",14,300000)
        call SetI("XP",15,400000)
        call SetI("XP",16,500000)
        call SetI("XP",17,600000)
        call SetI("XP",18,2000000)

        loop
            exitwhen A > udg_InitialPlayers
            call SetI("Rank",udg_Sorted[A],10)
            call RankSet(udg_Sorted[A], false)
            set A = A + 1
        endloop
    endfunction

    private function EnterTower takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        if GetPlayerController(p)==MAP_CONTROL_USER and IsUnitType(u,UNIT_TYPE_FLYING)==false then
            call UnitAddAbility(u,'A080') //300 sight range bonus
            call UnitAddAbility(u,'A081') //+10 armor
        endif
        set u = null
    endfunction

    private function LeaveTower takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        if GetPlayerController(p)==MAP_CONTROL_USER and IsUnitType(u,UNIT_TYPE_FLYING)==false then
            call UnitRemoveAbility(u,'A080') //300 sight range bonus
            call UnitRemoveAbility(u,'A081') //+10 armor
        endif
        set u = null
    endfunction

    private function GameInitA takes nothing returns nothing
        local integer i = 1
        local trigger t

        set udg_rpg_radius[0]=300
        loop
            exitwhen i>5
            set udg_rpg_damage[i] = 1200+400*i
            set udg_rpg_radius[i] = 300+20*i
            set i=i+1
        endloop
        call SetI("Shop",'Hpal',10) //Rifleman
        call SetI("Shop",'H004',1) //Forward Observer
        call SetI("Shop",'H003',1) //Designated Marksman
        call SetI("Shop",'H006',1) //Force Recon
        call SetI("Shop",'H002',2) //Navy Corpsman
        call SetI("Shop",'H007',1) //Engineer
        call SetI("Shop",'H000',2) //Flamethrower
        call SetI("Shop",'H008',1) //Delta Operator
        call SetI("Shop",'H005',2) //Machine Gunner
        call SetI("Shop",'H00J',1) //Infantry Unit Leader
        call SetI("Shop",'H00N',1) //MQ-3 Predator
        call SetI("Shop",'H00O',2) //Assaultman
        call SetI("Shop",'H00S',1) //Scout Sniper
        call NumberPlayers()
        call InitRanks()
        if 4>udg_InitialPlayers then
            set udg_ServicePlayerRequirement = 4
        else
            set udg_ServicePlayerRequirement = udg_InitialPlayers
        endif
        set udg_GlobalUnit[20] = gg_unit_H007_0025
        set udg_GlobalUnit[21] = gg_unit_Hpal_0033
		call SetUnitInvulnerable(udg_GlobalUnit[20], true)
		call SetUnitInvulnerable(udg_GlobalUnit[21], true)
        call UnitAddAbility(udg_GlobalUnit[20],'Awan')
        call UnitAddAbility(udg_GlobalUnit[21],'Awan')
        call UnitGenerateAlarms(gg_unit_ntav_0005,false)
        call UnitGenerateAlarms(gg_unit_hhou_0001,false)
        call UnitGenerateAlarms(gg_unit_hatw_0095,false) //Comm. Tower
        set udg_CommTower = gg_unit_hatw_0095
        set udg_SquadLeaderX[1] = GetRandomReal(-7500.0,10600.0)
        set udg_SquadLeaderY[1] = GetRandomReal(-2700.0,12500.0)
        set udg_SquadLeaderX[2] = GetRandomReal(-7500.0,10600.0)
        set udg_SquadLeaderY[2] = GetRandomReal(-2700.0,12500.0)
        set udg_AirfieldF22[1] = gg_unit_h00M_0073
        set udg_AirfieldF22[2] = gg_unit_h00M_0083
        set udg_AH1Cobra[1] = gg_unit_h00L_0097
        set udg_AH1Cobra[2] = gg_unit_h00L_0096
        set udg_AH1Cobra[3] = gg_unit_h00L_0098
        call SetUnitTimeScalePercent(udg_AH1Cobra[1],0.0) //Originally 1.0
        call SetUnitTimeScalePercent(udg_AH1Cobra[2],0.0)
        call SetUnitTimeScalePercent(udg_AH1Cobra[3],0.0)
        call SetUnitTimeScalePercent(udg_AirfieldF22[1],0.0)
        call SetUnitTimeScalePercent(udg_AirfieldF22[2],0.0)
        call PauseUnit(udg_AirfieldF22[1],true)
        call PauseUnit(udg_AirfieldF22[2],true)
        set udg_DMKillingSpree[99] = 6 //Immortal Reanimation Rate
        call SetUnitColor(gg_unit_h00I_0094, PLAYER_COLOR_LIGHT_GRAY)
        set bj_rescueChangeColorUnit = false
        call SetAllyColorFilterState(0)
        call EnableMinimapFilterButtons(false,false)
        call SetTimeOfDay(20.00)
        call SetTimeOfDayScale(0.055)
        call EnableDawnDusk(true)
        set i = 0
        loop
            exitwhen i>9
            set udg_Clock[i] = "0" + I2S(i)
            set i=i+1
        endloop
        set i=10
        loop
            exitwhen i>59
            set udg_Clock[i] = I2S(i)
            set i=i+1
        endloop
        set i=1
        loop
            exitwhen i>12
            call SetI("1",i,0)
            call SetI("2",i,0)
            call SetI("3",i,0)
            call SetI("4",i,0)
            call SetI("5",i,0)
            call SetI("6",i,0)
            call SetI("7",i,0)
            call SetI("8",i,0)
            call SetI("9",i,0)
            call SetI("10",i,0)
            call SetI("11",i,0)
            call SetI("12",i,0)
            call SetI("13",i,0)
            set i=i+1
        endloop
        call ItemInitialize()
        call EnableSitrep()
        call EnableTC()
        

        call TriggerSleepAction(0.)
        call PauseUnit(udg_AH1Cobra[1],true)
        call PauseUnit(udg_AH1Cobra[2],true)
        call PauseUnit(udg_AH1Cobra[3],true)
        call UnitAddItemById(gg_unit_nvl2_0022,'rump')
        call UnitAddItemById(gg_unit_nvl2_0023,'rump')
        call UnitAddItemById(gg_unit_nvl2_0014,'rump')
        set udg_MOSText[0]="None"
        set udg_MOSText[1]="Rifleman/Machine Gunner/IUL"
        set udg_MOSText[2]="Navy Corpsman"
        set udg_MOSText[3]="Flamethrower"
        set udg_MOSText[4]="Assaultman/Combat Engineer"
        set udg_MOSText[5]="MQ-3 Predator"
        set udg_MOSText[6]="Designated Marksman"
        set udg_MOSText[7]="Force Recon/Delta Operator/Forward Observer"
        set udg_CivilianChatter[1] = "We've been hearing strange noises."
        set udg_CivilianChatter[2] = "Mama always said life was like a box of chocolates. You never know what you're gonna get."
        set udg_CivilianChatter[3] = "The phone lines only work half the time. What's going on?"
        set udg_CivilianChatter[4] = "A census taker once tried to test me. I ate his liver with some fava beans and a nice Chianti."
        set udg_CivilianChatter[5] = "What's going on in Boston?"
        set udg_CivilianChatter[6] = "I'm afraid."
        set udg_CivilianChatter[7] = "The government said we should go North."
        set udg_CivilianChatter[8] = "I'm as mad as hell, and I'm not going to take this anymore!"
        set udg_CivilianChatter[9] = "I've seen one of those things before.."
        set udg_CivilianChatter[10] = "My brother was a Marine."
        set udg_CivilianChatter[11] = "Is it the terrorists? Where did the virus come from?"
        set udg_CivilianChatter[12] = "Mr. Marine, you're trying to seduce me. Aren't you?"
        set udg_CivilianChatter[13] = "You talking to me?"
        set udg_CivilianChatter[14] = "Don't point that thing at me."
        set udg_CivilianChatter[15] = "Do we have to leave Ravenholm?"
        set udg_CivilianChatter[16] = "I don't believe the shit on CNN."
        set udg_CivilianChatter[17] = "The airfield still has a functioning repair bay."
        set udg_CivilianChatter[18] = "The woods are quiet tonight."
        set udg_CivilianChatter[19] = "Can I get you a drink?"
        set udg_CivilianChatter[20] = "I don't think we can contain the outbreak."
        set t=CreateTrigger()
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower1)
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower2)
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower3)
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower4)
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower5)
        call TriggerRegisterEnterRectSimple(t,gg_rct_Tower6)
        call TriggerAddAction(t,function EnterTower)
        set t=CreateTrigger()
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower1)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower2)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower3)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower4)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower5)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_Tower6)
        call TriggerAddAction(t,function LeaveTower)
        set t=null
        set i=0
        loop //Hydrocyanic
            exitwhen i>10
            set udg_AilmentChance[((i*7)+2)]=6
            set i=i+1
        endloop
        set i=0
        loop //Open Wounds
            exitwhen i>10
            set udg_AilmentChance[((i*7)+3)]=6
            set i=i+1
        endloop
        set i=0
        loop //Fracture
            exitwhen i>10
            set udg_AilmentChance[((i*7)+4)]=10
            set i =i+1
        endloop
        set i=0
        loop //Parasite
            exitwhen i>10
            set udg_AilmentChance[((i*7)+5)]=12
            set i=i+1
        endloop
        set i=0
        loop //Veratrum
            exitwhen i>10
            set udg_AilmentChance[((i*7)+6)]=7
            set i=i+1
        endloop
        set i=0
        loop //Short Circuit
            exitwhen i>10
            set udg_AilmentChance[((i*7)+7)]=20
            set i=i+1
        endloop
    endfunction

    private function Trig_Quest_Menu_Actions takes nothing returns nothing
        // SITREP
        local string s 

        call TriggerSleepAction(0.1)

        set s = ""
        set s = s + "Patrol Sector E. Talk to the civilians in Ravenholm and gather intelligence on the area. Confirmed Zulu sightings have been reported in nearby Sectors but intelligence expects no activity here.|n"
        set s = s + "Rendezvous with squad at Ravenholm for extraction at 2200 hours. Receive and comply with instructions from the chain of command. Report any activity to Battalion (callsign Iron Hand)."
        call CreateQuestBJ(bj_QUESTTYPE_REQ_DISCOVERED, "Current Orders", s, "ReplaceableTextures\\CommandButtons\\BTN_Abstract_MarineLogo.blp" )
        call CreateQuestItemBJ( GetLastCreatedQuestBJ(), "[|cffffcc00Current Orders|r]" )
        
        set udg_CurrentOrders = GetLastCreatedQuestBJ()
        

        set s = ""
        set s = s + "Medium rain conditions expected."
        call CreateQuestBJ( bj_QUESTTYPE_REQ_DISCOVERED, "Strategic Information", s , "ReplaceableTextures\\PassiveButtons\\PASBTNElunesBlessing.blp" )
        call CreateQuestItemBJ( GetLastCreatedQuestBJ(), "[|cffffcc00ALICE Weather Forcast|r]" )
        set udg_QuestDifficulty = GetLastCreatedQuestBJ()
        
        
        set s = ""
        set s = s + "ALICE (Advanced Lifeform Interface for Combat Environments) is your Combat Suit's semi-intelligent computer. Basic interface commands are authorised for all Enlisted marines.|n|n"
        set s = s + "-load (biometric ID) : Loads your ID into suit interface|n" 
        set s = s + "-save : ALICE provides you with your biometric ID for future use|n"
        set s = s + "-check (biometric ID) : Verifies that the code you recorded after saving is correct|n"
        set s = s + "-ms : displays the squad's movement speed|n"
        set s = s + "-team : displays the MOS of each Marine|n"
        set s = s + "-report : Squad combat statistics|n"
        set s = s + "-stats : displays your statistics|n"
        set s = s + "-showstats : displays your statistics to all players|n"
        set s = s + "-medals : medal count for every player|n"
        set s = s + "-mos x : sets your MOS specialization - enter '-mos' to view the selection list|n"
        set s = s + "-sitrep x : Allows team leaders to set squad status text|n"
        set s = s + "-sitrep 1 : Displays Experience in ALICE interface|n"
        set s = s + "-sitrep 2 : Displays Kills in ALICE interface|n"
        set s = s + "-sitrep 3 : Displays Movespeed in ALICE interface|n"
        set s = s + "-ac : ailment check|n"
        set s = s + "-shells x : adjusts the number of shells per artillery barrage (1 to 20)|n"
        set s = s + "-dp x : Adjusts artillery barrage dispersion range|n"
        set s = s + "-fps : first person mode. Toggle On/Off|n"
        set s = s + "-tc x : used by fire team leaders to change the team color. Replace X with any value between 0 and 13|n"
        set s = s + "-tl : pings the location of all fire team members|n"
        
        // ALICE
        call CreateQuestBJ( bj_QUESTTYPE_OPT_DISCOVERED,"ALICE", s, "ReplaceableTextures\\CommandButtons\\BTN_Abstract_Computer.blp" )

        call CreateQuestItemBJ( GetLastCreatedQuestBJ(), "[|cffffcc00ALICE Operations Manual|r] |cffff0000Classified|r|nProperty of the United States Government" )
        

        // Manufacture
        call CreateQuestBJ( bj_QUESTTYPE_OPT_DISCOVERED, "System Information", "This ALICE unit was activated on 2nd August 2031 in Fort Bragg.|n|nMission strategy, discussion and credits can be found on the website. Website : http://www.notd-aftermath.com ", "ReplaceableTextures\\CommandButtons\\BTN_Ability_Reconnaisance.blp" )
        call CreateQuestItemBJ( GetLastCreatedQuestBJ(), "[|cffffcc00 Obsidian Corporation |r]" )

        // Credits
        //call CreateQuestBJ( bj_QUESTTYPE_OPT_DISCOVERED, "Key Personnel", "http://notd-aftermath.blogspot.ca/", "ReplaceableTextures\\CommandButtons\\BTN_Abstract_Moh.blp" )
        //call CreateQuestItemBJ( GetLastCreatedQuestBJ(), "[|cffffcc00Battalion Chain of Command|r] |cffff0000Classified|r|nENCRYPTED - Run Y7ES protocol on the data below." )
        
            
        /*
            Preview Screen - Azazel_ (USMC Logo)
            Loading Screen - "The Woods"(c)  by Craig K. Marble

            Models and Skins -
            Marine Camoflouge Model - Lost_Tribute
            F-22 Raptor Model - Illidan(Evil)X
            Apache Model - Illidan(Evil)X
            Cobra Model - Illidan(Evil)X
            Bradley Model - Illidan(Evil)X
            Blackhawk Model - Kofi_Banan
            Ship Model - Kofi_Banan
            Sentry Gun Model - Domokun
            AirField Tower Model - !!GORO!!
            Iron Fence Model - Illidan(Evil)X
            Earth Model - RightField
            Explosion Effects - WILL THE ALMIGHTY 
            Nuclear Aura Effect - General Frank
            Projectile Effects - Talon the Mage, General Frank

            Icons -
            Conquest-NOVA, Azazel_, General Frank, WILL THE ALMIGHTY, 
            oh_snap, Big Dub, ANdROnIQ, ChirusHighwind, zombie2279, Mobilize,
            lieutang, Riley, Hybred, Pins, yakonshus, -JonNny, Thorneon

            Code System - 
            Old - PipeDream
            New - Conquest-NOVA

            Compression - 
            Conquest-NOVA , Vexorian
        */

    endfunction

	
	
	
	
	

	private function Specimen13A takes nothing returns nothing
		local integer i = 1
		local integer i2 = 1
		local unit u
		local location l
		local real x
		local real y
		local rect r
		
		// disabled for now
		return
		
		if GetRandomInt(0,25)!=1 or udg_CurrentWave>16 or udg_SquadXP<35000 then
			return
		endif
		call PolledWait(7.)
		call ALICEText(10.0, "Specimen 13-A destroyed. Executing Order 66." )
		call PolledWait(5.)
		call GeneralText(5.0, "|cffcd950cBattalion|r : What's going on..what's Order 66?" )
		call PolledWait(8.)
		call GeneralText(5.0, "|cffcd950cAgent|r : ne soiz ja. Marines die." )
		call PolledWait(7.)
		call ALICE2Text(10.0, "Communications Link Shut Down.." )
		loop
			exitwhen i2>udg_Players
			set x = GetUnitX(udg_Hero[udg_Sorted[i2]])
			set y = GetUnitY(udg_Hero[udg_Sorted[i2]])
			set l = Location(x,y)
			set r = Rect( x - 1000, y - 1000, x + 1000, y + 1000 )
			set i = 1
			loop
				exitwhen i>udg_InitialPlayers
				call PingMinimapEx(x,y,10.0,255,0,0,false)
				set u = CreateUnit(ConvertedPlayer(udg_Sorted[i]),'e002',x,y,0.0)
				call UnitApplyTimedLife(u,'Bhwd',20.0)
				call TriggerSleepAction(0.)
				set i=i+1
			endloop
			call SetCameraQuickPosition(x,y)
			call PolledWait(3.)
			set u = CreateUnit(Player(11),'e00K',x,y,0.0) //Mushroom Cloud
			call UnitApplyTimedLife(u,'Bhwd',7.0)
			call PolledWait(0.5)
			call WhiteFlash.execute()
			//set u = CreateUnit(Player(11),'e004',x,y,0.0) //Shiva Radiation
			//call UnitApplyTimedLife(u, 'Bhwd', 240.0)
			//call TerrainDeformationCraterBJ(2.0, true, l, 900.0, 35.0)
	 
			call SetTerrainType(x, y, 'Xdrt',  -1, 11, 0)
			call EnumItemsInRect(r,null,function killitem)
			set udg_myinteger = 10
			call EnumDestructablesInRect(r,null,function killtree)
			call UnitDamagePoint( udg_Residence41, 0, 1300.0, x, y, 75000.0, true, false, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS )
			call RemoveLocation(l)
			call StartSound(gg_snd_Shiva)
			set i = 1
			loop
				exitwhen i>15
				set l = GetRandomLocInRect(r)
				set u = CreateUnit(Player(11),'o002',GetLocationX(l),GetLocationY(l),0.0)
				call UnitApplyTimedLife(u, 'Bhwd', 240.0)
				call RemoveLocation(l)
				if GetRandomInt(0,1)==1 then
					call TriggerSleepAction(0.)
				endif
				set i=i+1
			endloop
			call SetNoise(8.5)
			call PolledWait(2.75)
			call IntermissionRestore.execute()
			call ClearNoise()
			call RemoveRect(r)
			set i2=i2+1
		endloop
		set u = null
		set r = null
		set l = null
	endfunction
	
    private function Trig_Initialisation_B_Actions takes nothing returns nothing
	
		local real x 
		local real y
		local trigger t
        call EndThematicMusicBJ(  )
        call Trig_Quest_Menu_Actions()
        call putInteger(null,"FO_total_shells",900)
        call putInteger(null,"FO_dp",250)
        call putInteger(null,"FO_number_of_shells",5)
        call putInteger(null,"FO_barrage_delay",12)
        set udg_PlayerSpawnBoundary = Rect(-7500.00, -2700.00, 10600.00, 12500.00)
        set udg_ItemRectangle = Rect(-7500.00, -4700.00, 13000.00, 15000.00)
		
		set x = GetRandomReal(GetRectMinX(udg_PlayerSpawnBoundary),GetRectMaxX(udg_PlayerSpawnBoundary))
		set y = GetRandomReal(GetRectMinY(udg_PlayerSpawnBoundary),GetRectMaxY(udg_PlayerSpawnBoundary))
		
		set t = CreateTrigger()
		set udg_EvilSheep = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'H00F',x,y,0.0) //Specimen 13-A
		call TriggerRegisterUnitEvent(t, udg_EvilSheep, EVENT_UNIT_DEATH)
		call TriggerAddAction(t,function Specimen13A)
		
        set udg_soundpath = "war3mapImported\\IntroD.mp3"
        call PlaySoundPath.execute()
        set udg_BlackHawk = gg_unit_ntav_0005
        set udg_Residence41 = gg_unit_hhou_0001
        set udg_ForwardStation[1] = gg_unit_nten_0015
        set udg_ForwardStation[2] = gg_unit_nten_0018
        call UnitGenerateAlarms(udg_ForwardStation[1],false)
        call UnitGenerateAlarms(udg_ForwardStation[2],false)
        set udg_IntroStart[1] = gg_cam_IntroA1
        set udg_IntroStart[2] = gg_cam_IntroB1
        set udg_IntroStart[3] = gg_cam_IntroC1
        set udg_IntroStart[4] = gg_cam_IntroD1
        set udg_IntroStart[5] = gg_cam_IntroE1
        set udg_IntroStart[6] = gg_cam_IntroF1
        set udg_IntroStart[7] = gg_cam_IntroG1
        set udg_IntroEnd[1] = gg_cam_IntroA2
        set udg_IntroEnd[2] = gg_cam_IntroB2
        set udg_IntroEnd[3] = gg_cam_IntroC2
        set udg_IntroEnd[4] = gg_cam_IntroD2
        set udg_IntroEnd[5] = gg_cam_IntroE2
        set udg_IntroEnd[6] = gg_cam_IntroF2
        set udg_IntroEnd[7] = gg_cam_IntroG2
        set udg_IntroView[1] = gg_rct_IntroCam1
        set udg_IntroView[2] = gg_rct_IntroCam2
        set udg_IntroView[3] = gg_rct_IntroCam3
        set udg_IntroView[4] = gg_rct_IntroCam4
        set udg_IntroView[5] = gg_rct_IntroCam5
        set udg_IntroView[6] = gg_rct_IntroCam6
        set udg_IntroView[7] = gg_rct_IntroCam7
        set udg_ZombieAmbience[1] = gg_snd_Zombie1
        set udg_ZombieAmbience[2] = gg_snd_Zombie2
        set udg_ZombieAmbience[3] = gg_snd_Zombie3
        set udg_ZombieAmbience[4] = gg_snd_Zombie4
        set udg_ZombieAmbience[5] = gg_snd_Zombie5
        set udg_ZombieAmbience[6] = gg_snd_Zombie6
        set udg_Ambience[1] = gg_snd_Ambience1
        set udg_Ambience[2] = gg_snd_Ambience2
        set udg_Ambience[3] = gg_snd_Ambience3
        set udg_Ambience[4] = gg_snd_Ambience4
        set udg_Ambience[5] = gg_snd_Ambience5
        set udg_Ambience[6] = gg_snd_Ambience6
        set udg_Ambience[7] = gg_snd_Ambience7

        set udg_HeroAvailable[1] = 10 //Rifleman
        set udg_HeroAvailable[2] = 2 //Flamethrower
		set udg_HeroAvailable[3] = 1
		set udg_HeroAvailable[4] = 1
        set udg_HeroAvailable[5] = 2 //Navy Corpsman
		set udg_HeroAvailable[7] = 1
        set udg_HeroAvailable[6] = 2 //Machine Gunner
		set udg_HeroAvailable[8] = 1
		set udg_HeroAvailable[9] = 1
		set udg_HeroAvailable[10] = 1 
        set udg_HeroAvailable[11] = 2  //Assaultman
		set udg_HeroAvailable[12] = 1
        set udg_HeroType[1] = 'Hpal'
        set udg_HeroType[2] = 'H000'
        set udg_HeroType[3] = 'H007'
        set udg_HeroType[4] = 'H003'
        set udg_HeroType[5] = 'H002'
        set udg_HeroType[6] = 'H005'
        set udg_HeroType[7] = 'H00N'
        set udg_HeroType[8] = 'H006'
        set udg_HeroType[9] = 'H00J'
        set udg_HeroType[10] = 'H004'
        set udg_HeroType[11] = 'H00O'
        set udg_HeroType[12] = 'H008'
        set udg_Medal[1] = 'R00D'
        set udg_Medal[2] = 'R008'
        set udg_Medal[3] = 'R00E'
        set udg_Medal[4] = 'R00F'
        set udg_Medal[5] = 'R00G'
        set udg_Medal[6] = 'R00I'
        set udg_Medal[7] = 'R00J'
        set udg_Medal[8] = 'R00K'
        set udg_Medal[9] = 'R00L'
        set udg_Medal[10] = 'R00U'
        set udg_Medal[13] = 'R00X'
        set udg_MedalName[1] = "Marine Corps Commendation Medal"
        set udg_MedalName[2] = "Bronze Star"
        set udg_MedalName[3] = "Marine Corps Medal of Heroism"
        set udg_MedalName[4] = "Silver Star"
        set udg_MedalName[5] = "Navy Cross"
        set udg_MedalName[6] = "Armed Services Commendation Medal"
        set udg_MedalName[7] = "Department of Defense Meritorious Service Medal"
        set udg_MedalName[8] = "Department of Defense Superior Service Medal"
        set udg_MedalName[9] = "Department of Defense Distinguished Service Medal"
        set udg_MedalName[10] = "Medal of Honor"
        set udg_MedalName[13] = "Drill Instructor Ribbon"
        set udg_UnknownEntities = GetPlayersAllies(Player(bj_PLAYER_NEUTRAL_VICTIM))
        set udg_UndeadRandomSpawn[1] = gg_rct_UndeadRandomSouth
        set udg_UndeadRandomSpawn[2] = gg_rct_UndeadRandomNorth
        set udg_UndeadRandomSpawn[3] = gg_rct_UndeadRandomEast
        set udg_UndeadRandomSpawn[4] = gg_rct_UndeadRandomWest
        set udg_LandingZones[1] = gg_rct_LZ_One
        set udg_LandingZones[2] = gg_rct_LZ_Two
        set udg_LandingZones[3] = gg_rct_LZ_Three
        set udg_LandingZones[4] = gg_rct_LZ_Four
        set udg_LandingZones[5] = gg_rct_LZ_Five
        set udg_LandingZones[6] = gg_rct_LZ_Six
        set udg_LandingZones[7] = gg_rct_LZ_Seven
        set udg_LandingZones[8] = gg_rct_LZ_Eight
        set udg_AilmentOrder[1] = "attack"
        set udg_AilmentOrder[2] = "unholyfrenzy"
        set udg_AilmentOrder[3] = "attack"
        set udg_AilmentOrder[4] = "slow"
        set udg_AilmentOrder[5] = "parasite"
        set udg_AilmentOrder[6] = "drunkenhaze"
        set udg_AilmentOrder[7] = "purge"
        set udg_Ailment[1] = 'A01F'
        set udg_Ailment[2] = 'A02O'
        set udg_Ailment[3] = 'A01G'
        set udg_Ailment[4] = 'A01J'
        set udg_Ailment[5] = 'A01X'
        set udg_Ailment[6] = 'A03I'
        set udg_Ailment[7] = 'A02C'
        set udg_PetType[1] = 'n00B'
        set udg_PetType[2] = 'n00I'
        set udg_PetType[3] = 'n00G'
        set udg_PetType[4] = 'n00E'
        set udg_PetType[5] = 'n00H'
        set udg_PetType[6] = 'n00Q'
    endfunction

    globals
        private button array            udg_DialogButton
        private integer array           udg_DialogResponse
    endglobals

	// dead code
    private function BootCamp takes nothing returns nothing
        local integer i = 1
        local player p
       // call DestroyTrigger(gg_trg_Combat)
        set udg_Mode = 2
        call QuestSetTitle(udg_QuestDifficulty,"Boot Camp")
        call ALICEText(20.0, "Boot Camp Mode Initialized. The senior ranking officer will provide further instruction." )
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))-0.15)
        call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))-0.15)
        loop
            exitwhen i>udg_InitialPlayers
            set p = ConvertedPlayer(udg_Sorted[i])
            call SetPlayerTechMaxAllowed(p,'H007',-1) //Combat Engineer
            call SetPlayerTechMaxAllowed(p,'H003',-1) //Marksman
            call SetPlayerTechMaxAllowed(p,'H005',-1) //Machine Gunner
            
            call SetPlayerTechMaxAllowed(p,'H00O',-1) //Assault man
            call SetPlayerTechMaxAllowed(p,'H00N',-1) //Pred
            call SetPlayerTechMaxAllowed(p,'H00J',-1) // iul
            call SetPlayerTechMaxAllowed(p,'H008',-1) // delta
            call SetPlayerTechMaxAllowed(p,'H006',-1) //recon
            call SetPlayerTechMaxAllowed(p,'H004',-1) //Fo
         
            set i=i+1
        endloop
        call PolledWait(20.)
        call ALICEText(15.0, "Marines have +5 armor in Boot Camp mode. There is limited experience gain and medals cannot be earned." )
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,20.0," ")
        call PolledWait(20.)
        set i=1
        loop
            exitwhen i>udg_InitialPlayers
            set p = ConvertedPlayer(udg_Sorted[i])
            call UnitAddAbility(udg_Hero[udg_Sorted[i]],'A062') //Boot Camp Bonus Armor
            call SetPlayerHandicapXP(p,1.5)
            call ModifyHeroSkillPoints(udg_Hero[udg_Sorted[i]],bj_MODIFYMETHOD_ADD,1)
            if udg_Experience[udg_Sorted[i]]>=10000 and udg_Experience[udg_Sorted[i]]<50000 then
                call SetPlayerTechResearched(p,'R00P',1)
            endif
            set i=i+1
        endloop
    endfunction

    private function DifficultyResponse takes nothing returns nothing
        set udg_DialogResponse[2] = 1
        if GetClickedButton()==udg_DialogButton[1] then //Normal
            set udg_Difficulty = 3
        elseif GetClickedButton()==udg_DialogButton[2] then //Nightmare
            set udg_Difficulty = 5
		endif
		
        //elseif GetClickedButton()==udg_DialogButton[3] then //Boot Camp
        //    set udg_Difficulty = 1
        //    call BootCamp.execute()
       // endif
    endfunction

    private function EvilSheep takes nothing returns nothing
        local real x = GetRandomReal(GetRectMinX(udg_PlayerSpawnBoundary),GetRectMaxX(udg_PlayerSpawnBoundary))
        local real y = GetRandomReal(GetRectMinY(udg_PlayerSpawnBoundary),GetRectMaxY(udg_PlayerSpawnBoundary))

        set x = GetRandomReal(GetRectMinX(udg_PlayerSpawnBoundary),GetRectMaxX(udg_PlayerSpawnBoundary))
        set y = GetRandomReal(GetRectMinY(udg_PlayerSpawnBoundary),GetRectMaxY(udg_PlayerSpawnBoundary))
        set udg_GoodSheep = CreateUnit(Player(6),'H00G',x,y,0.0)
        call UnitShareVision(udg_GoodSheep,Player(6),false)
    endfunction

    private function MultiboardTitleSpin takes string s, real time returns nothing
        local real dt = 0.2
        local integer A = 1
        local integer Amax = R2I(time/dt)
        local integer pindex
        loop
            exitwhen A>Amax
            call TriggerSleepAction(dt)
            set pindex = ModuloInteger(A,4)+1
            call MBSet( udg_SquadStatus, 1, 1, s + " " + SubString(udg_progress, pindex-1, pindex) )
            set A=A+1
        endloop
        call MBSet(udg_SquadStatus,1,1,s+" *")
    endfunction

    private function MBIcon takes multiboard mb, integer col, integer row, string iconFileName returns nothing
        local multiboarditem mbitem = MultiboardGetItem(mb, row - 1, col - 1)
        call MultiboardSetItemIcon(mbitem, iconFileName)
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
    endfunction

    private function MBWidth takes multiboard mb, integer col, integer row, real width returns nothing
        local multiboarditem mbitem = MultiboardGetItem(mb, row - 1, col - 1)
        call MultiboardSetItemWidth(mbitem, width/100.0)
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
    endfunction

    private function MBStyle takes multiboard mb, integer col, integer row, boolean showValue, boolean showIcon returns nothing
        local multiboarditem mbitem = MultiboardGetItem(mb, row - 1, col - 1)
        call MultiboardSetItemStyle(mbitem, showValue, showIcon)
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
    endfunction

    private function ALICEInit2 takes nothing returns nothing
        local integer i = 1
        local real r
        loop
            exitwhen i>udg_InitialPlayers
            call MBSet(udg_SquadStatus,1,i+3,"Receiving..")
            set i=i+1
        endloop
        call PolledWait(2.)
        set i = 1
        loop
            exitwhen i>udg_InitialPlayers
            call PolledWait(GetRandomReal(0.1,0.9))
            call MBSet(udg_SquadStatus,1,i+3,GetPlayerName(ConvertedPlayer(udg_Sorted[i])))
            if udg_Hero[udg_Sorted[i]]==null then
                set r = 0.0
            else
                set r = GetWidgetLife(udg_Hero[udg_Sorted[i]]) / GetUnitState(udg_Hero[udg_Sorted[i]],UNIT_STATE_MAX_LIFE) * 100.0
            endif
            call MBSet(udg_SquadStatus,2,i+3,I2S(R2I(r)) + "%")
            call MBSet(udg_SquadStatus,3,i+3,I2S(R2I(udg_Experience[udg_Sorted[i]])))
            set i=i+1
        endloop
    endfunction

    private function ALICEInit takes nothing returns nothing
        local integer i = 2
        local integer i2
        set udg_SquadStatus = CreateMultiboard()
        call MultiboardSetRowCount(udg_SquadStatus,udg_InitialPlayers+3)
        call MultiboardSetColumnCount(udg_SquadStatus,3)
        call MultiboardSetTitleText(udg_SquadStatus,"ALICE Initializing..")
        call MultiboardDisplay(udg_SquadStatus,true)
        call MultiboardMinimize(udg_SquadStatus,false)
        call MBStyle(udg_SquadStatus,1,2,true,false)
        loop
            exitwhen i>3
            set i2=4
            loop
                exitwhen i2>udg_InitialPlayers+3
                call MBStyle(udg_SquadStatus,i,i2,true,false)
                set i2=i2+1
            endloop
            set i=i+1
        endloop
        set i=1
        loop
            exitwhen i>2
            call MBWidth(udg_SquadStatus,1,i,26.5)
            call MBWidth(udg_SquadStatus,2,i,0.0)
            call MBWidth(udg_SquadStatus,3,i,0.0)
            set i=i+1
        endloop
        call MBWidth(udg_SquadStatus,1,3,14.0)
        call MBWidth(udg_SquadStatus,2,3,5.25)
        call MBWidth(udg_SquadStatus,3,3,7.25)
        set i=1
        loop
            exitwhen i>udg_InitialPlayers
            call MBWidth(udg_SquadStatus,1,i+3,16.25)
            call MBWidth(udg_SquadStatus,2,i+3,5.25)
            call MBWidth(udg_SquadStatus,3,i+3,5.0)
            set i=i+1
        endloop
        if udg_Mode!=3 then
            call PolledWait(1.)
            call ALICEInit2.execute()
        endif
        call MultiboardSetTitleText(udg_SquadStatus,"ALICE : Locating Signal..")
        
        call MBIcon(udg_SquadStatus,1,1,"ReplaceableTextures\\CommandButtonsDisabled\\DISBTN_Abstract_MarineLogo.blp") //objectives tab
        call MBIcon(udg_SquadStatus,1,3,"ReplaceableTextures\\CommandButtonsDisabled\\DISBTN_Abstract_MarineLogo.blp")
        call MBIcon(udg_SquadStatus,2,3,"ReplaceableTextures\\CommandButtonsDisabled\\DISBTNStatUp.blp")
        call MBIcon(udg_SquadStatus,3,3,"ReplaceableTextures\\CommandButtonsDisabled\\DISBTN_Ability_2ndLieutenant.blp")

        call MultiboardTitleSpin("Receiving Encrypted Data ",6.0)
        call MBSet(udg_SquadStatus,1,3,"Marine ID")
        call MBSet(udg_SquadStatus,2,3,"Health")
        call MBSet(udg_SquadStatus,3,3,"Experience")
        if udg_Mode==3 then
            return
        endif
        call PolledWait(2.)
        call MultiboardSetTitleText( udg_SquadStatus, "ALICE : Signal Found" )
        set i=1
        loop
            exitwhen i>udg_InitialPlayers
            call MBSet( udg_SquadStatus, 1, i+3, GetPlayerName(ConvertedPlayer(udg_Sorted[i])) )
            set i=i+1
        endloop
        call MBSet( udg_SquadStatus, 1, 1, "Running Decryption Cipher.." )
        call PolledWait(2.5)
        call MultiboardSetTitleText( udg_SquadStatus, "ALICE : Transmission Active" )
        //call TriggerRegisterTimerEvent(gg_trg_Multiboard_System,1.0,true)
    endfunction

    private function SatchelPrimer takes nothing returns nothing
        local player p = GetTriggerPlayer()
        local integer i = GetConvertedPlayerId(p)
        local group g = CreateGroup()
        local unit u
        local integer slength = StringLength(GetEventPlayerChatString())
        local integer thermal = 0
        local integer time = S2I(SubString(GetEventPlayerChatString(),7,slength))
        call GroupEnumUnitsSelected(g,p,null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            if GetUnitItem(u,'I010')!=null then
                set thermal=1
                set u = null
                exitwhen 1==1
            endif
            call GroupRemoveUnit(g,u)
        endloop
        if thermal==1 or GetUnitTypeId(udg_Hero[i])=='H007' then
            if time>=0 and time<61 and slength>7 then
                set udg_Primer = I2R(time)
                call ALICEText(4.0, "Satchel Charge Primer Set To: " + I2S(time) + " seconds." )
            else
                call ALICEText(4.0, "Satchel Charge Primer: " + I2S(R2I(udg_Primer)) + " seconds." )
            endif
        else
            call ALICEText(4.0, "Satchel Charge Primer: " + I2S(R2I(udg_Primer)) + " seconds." )
        endif
        call DestroyGroup(g)
        set g = null
    endfunction

    private function Leaver takes nothing returns nothing
        local integer i = 1
        local unit u
        local player p = GetTriggerPlayer()
        local integer id=GetConvertedPlayerId(p)
        local integer hashero=0
        local real x
        local real y
        set udg_MBcolors[id] = 3
        set udg_Leaver[id] = true
        call ForceRemovePlayer(udg_EchoCompany,p)
        call ForceAddPlayer(udg_EchoCasualties,p)
        call DisplayTextToPlayer(GetLocalPlayer(),0.0,0.0, GetPlayerName(p) + " has left the game." )
        
        if GetWidgetLife(udg_Hero[id])>0.405 then
            set hashero=1
            set x=GetUnitX(udg_Hero[id])
            set y=GetUnitY(udg_Hero[id])
            call PingMinimapEx(x, y, 5.0, 38, 100, 242, false)
        endif
        if udg_Mode!=3 then
            loop
                exitwhen i>udg_InitialPlayers
                if ConvertedPlayer(udg_Sorted[i])!=p then
                    call SetPlayerAllianceBJ(p,ALLIANCE_SHARED_CONTROL,true,ConvertedPlayer(udg_Sorted[i]))
                endif
                if hashero==1 then
                    set u = CreateUnit(ConvertedPlayer(udg_Sorted[i]),'e002',x,y,0.0)
                    call UnitApplyTimedLife(u,'Bhwd',15.0)
                    call TriggerSleepAction(0.)
                endif
                set i=i+1
            endloop
        endif
        set u=null
    endfunction

    private function IntroEngineB takes nothing returns nothing
        local real x = GetRectCenterX(udg_IntroView[udg_myinteger])
        local real y = GetRectCenterY(udg_IntroView[udg_myinteger])
        local player p = GetEnumPlayer()
        set bj_lastCreatedFogModifier = CreateFogModifierRect(p,FOG_OF_WAR_MASKED,bj_mapInitialPlayableArea,true,false)
        call FogModifierStart(bj_lastCreatedFogModifier)
        call DestroyFogModifier(bj_lastCreatedFogModifier)
    endfunction

    private function IntroEngineC takes nothing returns nothing
        local real x = GetUnitX(gg_unit_ntav_0005)
        local real y = GetUnitY(gg_unit_ntav_0005)
        local player p = GetEnumPlayer()
        local integer i = GetConvertedPlayerId(p)
        set bj_lastCreatedFogModifier = CreateFogModifierRect(p,FOG_OF_WAR_MASKED,bj_mapInitialPlayableArea,true,false)
        call FogModifierStart(bj_lastCreatedFogModifier)
        call DestroyFogModifier(bj_lastCreatedFogModifier)
		
		//set udg_SelectionView[i] = CreateFogModifierRadius(p,FOG_OF_WAR_VISIBLE,x,y,512,true,false)
        //call FogModifierStart(udg_SelectionView[i])
    endfunction

    private function CamFlashIntro takes nothing returns nothing
        local integer i = 1
        loop
            exitwhen i > udg_InitialPlayers
            if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
                call CinematicFilterGenericBJ( 0.1, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 0.0, 25, 0.0, 100, 100.0, 100.00, 100.00, 5.00 )
            endif
            set i = i + 1
        endloop
        call PolledWait(0.1)
        set i = 1
        loop
            exitwhen i > udg_InitialPlayers
            if ConvertedPlayer(udg_Sorted[i])==GetLocalPlayer() then
                call CinematicFilterGenericBJ( 0.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100, 100.00, 5, 0, 0, 0, 100.00 )
                call CinematicFilterGenericBJ( 0.0, BLEND_MODE_BLEND, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 20.00, 20.00, 20.00, 0.00, 20.00, 20.00, 20.00, udg_Visibility )
            endif
            set i = i + 1
        endloop
    endfunction

    private function IntroC takes nothing returns nothing
        local integer i = 1
        local unit mother = CreateUnit(Player(9),'nvlw',-1740.0,955.0,166.0)
        local unit child
        local unit man
        call TriggerSleepAction(0.)
        set child = CreateUnit(Player(9),'nvlk',-1740.0,955.0,166.0)
        call TriggerSleepAction(0.)
        set man = CreateUnit(Player(9),'nvil',-1260.0,312.0,166.0)
        call FogEnable(false)
        call FogMaskEnable(false)
        call CameraSetupApplyForceDuration(gg_cam_IntroCa,true,0.0)
        call PolledWait(0.65)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 1.2, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0 )
        call PolledWait(1.5)
        call SimpleChat(child,3.0,"|cfff3ad00Child|r : What's wrong with daddy?" )
        call PolledWait(3.)
        call SimpleChat(mother,3.0,"|cfff3ad00Mother|r : He's a little... sick." )
        call IssuePointOrder(man,"move",-1766.0,870.0)
        call PolledWait(3.)
        call SetUnitFacingTimed(child,220.0,1.0)
        call SetUnitFacingTimed(mother,220.0,1.0)
        call PolledWait(2.)
        call IssueImmediateOrder(man,"stop")
        call SetUnitFacingTimed(man,50.0,1.0)
        call SimpleChat(man,2.0,"|cfff3ad00Man|r : You shouldn't have to see this, Clara." )
        call PolledWait(2.)
        call SimpleChat(mother,2.0,"|cfff3ad00Clara|r : There were a lot of things we shouldn't have seen, Bernard." )
        call PolledWait(3.)
        call SimpleChat(mother,3.0,"|cfff3ad00Clara|r : Let's go for a walk, dear." )
        call PolledWait(2.)
        call IssuePointOrder(mother,"move",-2340.0,1285.0)
        call PolledWait(1.)
        call IssuePointOrder(man,"move",-700.0,1000.0)
        call IssuePointOrder(child,"move",-2300.0,1250.0)
        call PolledWait(1.)
        call SimpleChat(man,2.0,"|cfff3ad00Bernard|r : I'm sorry.." )
        call PolledWait(3.5)
        call CameraSetupApplyForceDuration(gg_cam_IntroCb,true,4.0)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEOUT, 1.5, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call PolledWait(0.5)
        set udg_soundpath = "war3mapImported\\m3-4.wav"
        call PlaySoundPath.execute()
        call PolledWait(0.75)
        call StartSound(gg_snd_FatherDead)
        call PolledWait(2.25)
        call FogEnable(true)
        call FogMaskEnable(true)
        call RemoveUnit(mother)
        call RemoveUnit(child)
        call RemoveUnit(man)
        set mother = null
        set child = null
        set man = null
    endfunction

    private function IntroB takes nothing returns nothing
        local integer i = 1
        call FogEnable(false)
        call FogMaskEnable(false)
        call SetAmbientNightSound("AshenvaleNight")
        call SetTerrainFogEx(0,6000,8000, 0.05, udg_FogColor, udg_FogColor, udg_FogColor)
        call PolledWait(0.65)
        call CameraSetupApplyForceDuration(gg_cam_IntroBa,true,0.0)
        call StartSound(gg_snd_SatCamZoom2)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 1.2, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0 )
        call CameraSetupApplyForceDuration(gg_cam_IntroBb,true,1.0)
        call PolledWait(0.65)
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,10.0, "Ravenholm" )
        call PolledWait(1.)
        call StartSound(gg_snd_SatCamShot)
        call CamFlashIntro.execute()
        call PolledWait(0.4)
        if GetRandomInt(0,1)==1 then
            call StartSound(gg_snd_SatCamShot2)
            call CamFlashIntro.execute()
        endif
        call PolledWait(2.)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEOUT, 1.5, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call PolledWait(1.5)
        call CameraSetupApplyForceDuration(gg_cam_IntroBc,true,0.0)
        call SetTerrainFogEx(0, udg_ZStart, udg_ZEnd, 0.55, udg_FogColor, udg_FogColor, udg_FogColor)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 1.5, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call PolledWait(1.)
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,8.0, "Population : 34 (est.)" )
        call PolledWait(4.)
        call GeneralText(5.0, "Status : Missing persons reported" )
        call PolledWait(4.)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEOUT, 1.8, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call PolledWait(1.5)
        call FogEnable(true)
        call FogMaskEnable(true)
    endfunction

    private function IntroA takes nothing returns nothing
        local integer i = 1
        local unit u = CreateUnit(Player(0),'hdhw',11553.0,11265.0,0.0)
        call CameraSetupApplyForceDuration(gg_cam_Intro_Camera,true,0.0)
		call SmoothUnitResize(u,2.0,2.8,8.5)
		call SetUnitTimeScalePercent(u,10.0)
		call PolledWait(1.0)
		
		//call SetUnitTimeScalePercent(u,300.0)
       
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 0.95, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0 )
        loop
            exitwhen i>11
            call UnitShareVision(u,Player(i),true)
            set i=i+1
        endloop
        call PolledWait(1.)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.75, "   Dedicated to the" )
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.75, "   United States Marine Corps" )
        call PolledWait(3.)
        call ClearTextMessages()
        call PolledWait(0.5)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.5, "   In the days following the initial outbreak," )
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.5, "   military operations continue at a brisk pace.." )
        call PolledWait(3.)
        call ClearTextMessages()
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.75, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call PolledWait(0.75)
        call RemoveUnit(u) //Earth
        set u = null
        call SetAmbientNightSound("AshenvaleNight")
        call SetTerrainFogEx(0, udg_ZStart, udg_ZEnd, 0.55, udg_FogColor, udg_FogColor, udg_FogColor)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 1.75, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        call SetForceAllianceStateBJ(udg_EchoCompany,udg_EchoCompany,bj_ALLIANCE_ALLIED_VISION)
        set udg_myinteger = GetRandomInt(1,7)
        call ForForce(udg_EchoCompany,function IntroEngineB)
        set udg_GlobalUnit[1] = CreateUnit(Player(0),'e00F',GetRectCenterX(udg_IntroView[udg_myinteger]),GetRectCenterY(udg_IntroView[udg_myinteger]),0.0)
        call CameraSetupApplyForceDuration(udg_IntroStart[udg_myinteger], true, 0.0)
        call CameraSetSourceNoise(8.0,0.1)
        call CameraSetupApplyForceDuration(udg_IntroEnd[udg_myinteger], true, 8.0)
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, "                                                                            |cff8b864eOperation Silent Hill|r")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 5.0, " ")
        call PolledWait(3.2)
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEOUT, 1.25, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
    endfunction

    private function SurvivalInit takes nothing returns nothing
        local integer i = 1
        local trigger t
        if GetWidgetLife(udg_Ogilvy)>0.405 then
            return
        endif
        set udg_myloc = GetRectCenter(gg_rct_SelectionZone)
        loop
            exitwhen i>udg_Players
            set udg_SelectionView[udg_Sorted[i]] = CreateFogModifierRadiusLoc(ConvertedPlayer(udg_Sorted[i]), FOG_OF_WAR_VISIBLE, udg_myloc, 350.0, true, false)
            call FogModifierStart(udg_SelectionView[udg_Sorted[i]])
            set i=i+1
        endloop
        call RemoveLocation(udg_myloc)
        call DisplayTextToPlayer(GetLocalPlayer(), 0.0, 0.0, "|cfff3ad00Select Marine Class|r" )
        
        call SetForceAllianceStateBJ(udg_FireTeamA,udg_FireTeamB,bj_ALLIANCE_ALLIED)
        call SetForceAllianceStateBJ(udg_FireTeamB,udg_FireTeamA,bj_ALLIANCE_ALLIED)
        set udg_Ogilvy = CreateUnit(Player(9),'n00Y',-1048.0,-223.0,320.0)
        call RemoveGuardPosition(udg_Ogilvy)
        call TriggerSleepAction(0.)
        call CreateUnit(Player(9),'nvlk',-394.0,442.0,280.0)
        call PolledWait(5.)
        
        // waves 1 to 5 entry point
        
        call ExecuteRegisteredFunction("Wave0")
        //call Wave0.execute()
    endfunction
    
    function OperationSilentHill takes nothing returns nothing
        local trigger t = CreateTrigger()
        local trigger t2 = CreateTrigger() //-prime
        local trigger t3
        local dialog DifficultyDialog
        local integer i = 1
        local integer allowboot = 1
        local real x
        local real y
        local player p
        local location l = Location(11735.0,15716.0)
        local group g = AMGetUnitsInRange(600,l,null)
        call PolledWait(0.1)
        call Trig_Initialisation_B_Actions()
        set udg_EchoCompany = GetPlayersByMapControl(MAP_CONTROL_USER)
        call ForGroup(g,function RemoveUnitAll)
        call ForceAddPlayer(udg_FireTeamA,Player(0))
        call ForceAddPlayer(udg_FireTeamA,Player(1))
        call ForceAddPlayer(udg_FireTeamA,Player(2))
        call ForceAddPlayer(udg_FireTeamA,Player(3))
        call ForceAddPlayer(udg_FireTeamA,Player(4))
        call SetPlayerColor(Player(0),PLAYER_COLOR_RED)
        call SetPlayerColor(Player(1),PLAYER_COLOR_RED)
        call SetPlayerColor(Player(2),PLAYER_COLOR_RED)
        call SetPlayerColor(Player(3),PLAYER_COLOR_RED)
        call SetPlayerColor(Player(4),PLAYER_COLOR_RED)
        call ForceAddPlayer(udg_FireTeamB,Player(5))
        call ForceAddPlayer(udg_FireTeamB,Player(6))
        call ForceAddPlayer(udg_FireTeamB,Player(7))
        call ForceAddPlayer(udg_FireTeamB,Player(8))
        call ForceAddPlayer(udg_FireTeamB,Player(10))
        call SetPlayerColor(Player(5),PLAYER_COLOR_BLUE)
        call SetPlayerColor(Player(6),PLAYER_COLOR_BLUE)
        call SetPlayerColor(Player(7),PLAYER_COLOR_BLUE)
        call SetPlayerColor(Player(8),PLAYER_COLOR_BLUE)
        call SetPlayerColor(Player(10),PLAYER_COLOR_BLUE)
        call SetPlayerColor(Player(13),ConvertPlayerColor(12))
        call SetPlayerOnScoreScreen(Player(13),false)
        call SetPlayerOnScoreScreen(Player(14),false)
        call SetPlayerOnScoreScreen(Player(9),false)
        call ForForce(udg_EchoCompany,function TriggerEventInitialize)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], udg_EchoCompany, bj_ALLIANCE_ALLIED )
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[9], bj_ALLIANCE_ALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], udg_EchoCompany, bj_ALLIANCE_ALLIED )
        call SetForceAllianceStateBJ(udg_EchoCompany, bj_FORCE_PLAYER[11], bj_ALLIANCE_ALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], GetPlayersAllies(Player(0)), bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(GetPlayersAllies(Player(0)), bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[9], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[11], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[9], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], bj_FORCE_PLAYER[14], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[11], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], bj_FORCE_PLAYER[14], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[14], bj_ALLIANCE_ALLIED_VISION )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], bj_FORCE_PLAYER[13], bj_ALLIANCE_ALLIED_VISION )
        call SetPlayerState(Player(13),PLAYER_STATE_GIVES_BOUNTY,0)
        call SetPlayerState(Player(14),PLAYER_STATE_GIVES_BOUNTY,0)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], udg_FireTeamA, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_FireTeamA, bj_FORCE_PLAYER[14], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], udg_FireTeamA, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_FireTeamA, bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[14], udg_FireTeamB, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_FireTeamB, bj_FORCE_PLAYER[14], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], udg_FireTeamB, bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(udg_FireTeamB, bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetPlayerName(Player(13),"Unknown Entities")
        call SetPlayerName(Player(14),"Unknown Entities")
        call FogEnable(true)
        call FogMaskEnable(true)
        set udg_Lighting = true
        call AbortCinematicFadeBJ()
        call CinematicFadeCommonBJ(0.0,0.0,0.0,0.0,"ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100,0.0)
        call VolumeGroupSetVolumeBJ(SOUND_VOLUMEGROUP_MUSIC,0.0)
        call VolumeGroupSetVolumeBJ(SOUND_VOLUMEGROUP_UNITSOUNDS,0.0)
        call ShowInterface(false,0.0)
        call PolledWait(0.1)
        call GameInitA.execute()
        if GetRandomInt(0,50)==1 then
            call IntroC()
        elseif GetRandomInt(0,5)==2 then
            call IntroB()
        else
            call IntroA()
        endif
        call PolledWait(1.3)
        call EvilSheep.execute()
        call ClearTextMessages()
        call PolledWait(0.15)
       
        //call DisableTrigger(gg_trg_Combat)
      
        call ResetToGameCamera(0)
		// to copter
        call PanCameraToTimed(GetUnitX(gg_unit_ntav_0005),GetUnitY(gg_unit_ntav_0005), 0.0)
        call SetForceAllianceStateBJ(udg_EchoCompany,udg_EchoCompany,bj_ALLIANCE_ALLIED)
        call RemoveUnit(udg_GlobalUnit[1])
        call ForForce(udg_EchoCompany, function IntroEngineC)
		
		/*
        call DialogSetMessage(udg_ModeDialog,"Select Mode")
        set udg_DialogButton[1] = DialogAddButton(udg_ModeDialog, "|cff778899Survival|r", 0 )
        set udg_DialogButton[2] = DialogAddButton(udg_ModeDialog, "|cff778899Deathmatch|r", 0 )
		*/
		
        call TriggerSleepAction(0.)
        set i=0
        loop
            exitwhen i > 11
			set p = Player(i)
            if GetPlayerSlotState(p) != PLAYER_SLOT_STATE_EMPTY and GetPlayerController(p) == MAP_CONTROL_USER and GetPlayerSlotState(p) != PLAYER_SLOT_STATE_LEFT then
                exitwhen 1==1
            endif
            set i=i+1
        endloop

		if i == 12 then
			set p = Player(0)
		endif
		
        set i=1
		
        loop
            exitwhen i>udg_InitialPlayers
            set udg_PlayerIcon[udg_Sorted[i]] = "UI\\Widgets\\EscMenu\\Human\\blank-background.blp"
            set i=i+1
        endloop
		
        if GetLocalPlayer()==p then
            call ShowInterface(true,0.2)
        else
            call StartSound(gg_snd_ALICEBeep)
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,10.0,"Initializing...")
        endif
		
        //call DialogDisplay(p,udg_ModeDialog,true)
        //loop
        //    exitwhen udg_DialogResponse[1]==1 or udg_myint==10 or udg_Players<2
        //   call TriggerSleepAction(1.)
        //    set udg_myint = udg_myint + 1
        //endloop
        //call DialogDisplay(p,udg_ModeDialog,false)
		
        //if udg_myint==10 or udg_Players<2 then
		
        call SurvivalInit.execute()
		
        //endif
        call CinematicFadeBJ(bj_CINEFADETYPE_FADEIN, 0.0, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0.0)
        set udg_Lighting = false
        call TriggerSleepAction(0.)
        call IntermissionRestore()
        call CameraSetTargetNoise(5.0,0.03)
        if udg_Mode!=3 then
            set DifficultyDialog = DialogCreate()
            
            set t3 = CreateTrigger()
            call TriggerRegisterDialogEvent(t,DifficultyDialog)
            call TriggerAddAction(t,function DifficultyResponse)
            
            call DialogSetMessage(DifficultyDialog,"Select Difficulty")
            set udg_DialogButton[1] = DialogAddButton( DifficultyDialog, "|cff778899Normal|r", 0 )
            set udg_DialogButton[2] = DialogAddButton( DifficultyDialog, "|cff778899Nightmare|r", 0 )
           // if allowboot==1 then
              //  set udg_DialogButton[3] = DialogAddButton( DifficultyDialog, "|cff778899Boot Camp|r", 0 )
           // endif
            call DialogDisplay(p,DifficultyDialog,true)
            set udg_myint=0
            loop
                exitwhen udg_DialogResponse[2]==1 or udg_myint==10
                call TriggerSleepAction(1.)
                set udg_myint = udg_myint + 1
            endloop
			
			if GetLocalPlayer()==p then
			
			else
				call ShowInterface(true,0.75)
			endif
		
            call DialogDisplay(p,DifficultyDialog,false)
            if udg_Difficulty>=4.0 then
                set udg_DifficultyString = "Difficulty : Nightmare"
                call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))+0.28)
                call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))+0.28)
                set udg_Pace = 0.8
                set udg_XPFactor = udg_XPFactor*2
            elseif udg_Difficulty>=2.0 then
				//set udg_Pace = 0.95
                set udg_DifficultyString = "Difficulty : Normal"
            else
                set udg_DifficultyString = "Difficulty : Boot Camp"
                set udg_XPFactor = 0.0
            endif
            if udg_XPFactor!=0.2 then //default normal
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 10.0, udg_DifficultyString )
            endif
            call QuestSetTitle( udg_QuestDifficulty, SubString(udg_DifficultyString, 13, 100) )
        endif
        set udg_ACA[10] = true
        set udg_ACA[12] = true
        call ALICEInit.execute()
        call DialogClear(DifficultyDialog)
       // call DialogClear(udg_ModeDialog)
        call ClearSelection()
        if udg_Mode!=3 then
            call SelectUnit(udg_BlackHawk,true)
        endif
        set i=1
        loop
            exitwhen i>10
            set x = GetRandomReal(-4000.0,10000.0)
            set y = GetRandomReal(-4000.0,10000.0)
            call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'ndog',x,y,0.0)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        set i=1
        loop
            exitwhen i>udg_Players
            call TriggerRegisterPlayerEventLeave( t, ConvertedPlayer(udg_Sorted[i]) )
            call TriggerRegisterPlayerChatEvent( t2, ConvertedPlayer(udg_Sorted[i]), "-prime", false )
            set i=i+1
        endloop
        call TriggerAddAction(t,function Leaver)
        call TriggerAddAction(t2,function SatchelPrimer)
        
        call SetAINeutralExtraEnabled(true)
        call SetAINeutralVictimEnabled(true)
        
        set t = null
        set t2 = null

        call RemoveRect(gg_rct_IntroCam1)
        call RemoveRect(gg_rct_IntroCam2)
        call RemoveRect(gg_rct_IntroCam3)
        call RemoveRect(gg_rct_IntroCam4)
        call RemoveRect(gg_rct_IntroCam5)
        call RemoveRect(gg_rct_IntroCam6)
        call RemoveRect(gg_rct_IntroCam7)

        set i=1
		// bunnies
        if GetRandomInt(0,25)==1 then
            loop
                exitwhen i>10
                set x = GetRandomReal(-2000.0,500.0)
                set y = GetRandomReal(-800.0,1200.0)
                call CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'n00T',x,y,0.0)
                call TriggerSleepAction(0.)
                set i=i+1
            endloop
        endif
    endfunction

endlibrary